package com.cjm.one.controller.customer;

import com.cjm.one.common.result.Result;
import com.cjm.one.service.FileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/file")
@Tag(name = "文件管理")
@Slf4j
public class FileController {
    @Resource
    private FileService fileService;
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "文件上传")
    public Result<String> uploadFile(
            @RequestPart("file") MultipartFile file,
            @RequestPart("category") String category
    ){
        return fileService.uploadFile(file,category);
    }

    @GetMapping("/download/{objectName}")
    @Operation(summary = "文件下载")
    public void downloadFile(@PathVariable String objectName,
                             HttpServletResponse response){
        fileService.downloadFile(objectName,response);
    }
}

